﻿<!DOCTYPE html>
<html>
<head>
<!--
  Copyright (c) 2017-2018 Jean-Marc VIGLINO,
  released under CeCILL-B (french BSD like) licence: http://www.cecill.info/
-->
  <title>ol-ext: Search Geoportail control</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <meta name="description" content="Control to add a grid reference to a map." />
  <meta name="keywords" content="ol3, control, search, BAN, french, places, autocomplete" />

  <!-- FontAwesome -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

  <!-- jQuery -->
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
  <!-- IE 9 bug on ajax tranport  -->
  <!--[if lte IE 9]>
  <script type='text/javascript' src='//cdnjs.cloudflare.com/ajax/libs/jquery-ajaxtransport-xdomainrequest/1.0.3/jquery.xdomainrequest.min.js'></script>
  <![endif]-->

  <!-- Openlayers -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@latest/ol.css" />
  <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ol@latest/dist/ol.js"></script>

  
  <!-- ol-ext -->
  <link rel="stylesheet" href="../../dist/ol-ext.css" />
  <script type="text/javascript" src="../../dist/ol-ext.js"></script>
  <!-- Pointer events polyfill for old browsers, see https://caniuse.com/#feat=pointer -->
  <script src="https://unpkg.com/elm-pep"></script>

  <script type="text/javascript" src="https://cdn.rawgit.com/Viglino/Geoportail-KISS/gh-pages/apikey.js"></script>
  
  <link rel="stylesheet" href="../style.css"/>
  <style>
    .ol-search ul {
      color: #333;
      font-size:0.85em;
      max-width: 21em;
    }
    .ol-search ul i {
      display: block;
      color: #333;
      font-size:0.85em;
    }
    .info a img {
      display: inline-block;
      height: 100px;
      max-width: 150px;
      margin: .5em;
    }
  </style>
</head>
<body >
  <a href="https://github.com/Viglino/ol-ext" class="icss-github-corner"><i></i></a>

  <a href="../../index.html">
    <h1>ol-ext: Search Geoportail control</h1>
  </a>

  <div class="info">
    <i>ol.control.SearchGeoportail</i> is a control to search place using the 
    <a href="https://geoservices.ign.fr/documentation/geoservices/geocodage.html">Geoportail API</a>.
    <div style="text-align: center">
      <b>In partnership with:</b><br/>
      <a href="https://www.geoportail.gouv.fr/"><img src="https://www.geoportail.gouv.fr/assets/images/logo-geoportail.svg" alt="Geoportail"></a>
      <a href="http://ign.fr"><img src="https://upload.wikimedia.org/wikipedia/commons/a/a0/IGN_logo_2012.svg" alt="IGN" class="jsx-3503728609 logo"></a>
    </div>	
    <ul>
      <li>
        You need an API key (<a href="http://professionnels.ign.fr/ign/contrats">get a key</a> 
        see <a href="https://geoservices.ign.fr/documentation/services-acces.html">documentation page</a>).
      </li>
    </ul>
    <br/>
    <i>ol.control.SearchGeoportail</i> use the <a href="map.control.search.html">ol.control.Search</a> control.
  </div>

  <!-- DIV pour la carte -->
  <div id="map" style="width:600px; height:400px;"></div>

  <div class="options">
    <i>Use the search control to start a new search.</i>
    <br/>
    <label>
      <input type="checkbox" class="position"/> priority to geo position (map center)
    </label>
    <br/>
    <label>
      <input type="checkbox" class="bbox"/> inside the current map extent
    </label>
  </div>
  
  <script type="text/javascript">
  // Layers
  var layers = [ new ol.layer.Geoportail({
    layer: 'GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2', 
  }), new ol.layer.Geoportail({
    layer: 'CADASTRALPARCELS.PARCELLAIRE_EXPRESS',
    visible: false
  })];

  // The map
  var map = new ol.Map ({
    target: 'map',
    view: new ol.View ({
      zoom: 5,
      center: [166326, 5992663]
    }),
    layers: layers
  });
  map.addControl(new ol.control.LayerSwitcher());

  // Set the search control
  var search = new ol.control.SearchGeoportail({
    //apiKey: apiKey,
    // type: 'Commune',
    // version: 2,
    reverse: true
  });
  map.addControl (search);

  // Select feature when click on the reference index
  search.on('select', function(e) {
    // console.log(e);
    map.getView().animate({
      center:e.coordinate,
      zoom: Math.max (map.getView().getZoom(),16)
    });
  });

  document.querySelector('input.position').addEventListener('change', function(e) {
    search.set('position', e.target.checked)
    search.search()
  })
  document.querySelector('input.bbox').addEventListener('change', function(e) {
    search.set('useExtent', e.target.checked)
    search.search()
  })
  </script>
  
</body>
</html>